﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snoop.Commons35
{
    public interface IFillable<TSource>
    {
        void Fill(TSource source);
    }

    public static class ArrayConverter
    {
        public static TTarget[] Convert<TSource, TTarget>(this TSource[] source) where TTarget : IFillable<TSource>
        {
            TTarget[] result = new TTarget[source.Length];
            int index = 0;
            foreach (TSource sourceItem in source)
            {
                TTarget targetItem= Activator.CreateInstance<TTarget>();
                targetItem.Fill(sourceItem);
                result[index] = targetItem;
                index++;
            }
            return result;
        }
    }
}
